﻿using System;
using System.Collections.Generic;
using System.Text;
using Common;

namespace BLL.LED
{
    public class FinanceRecordBase
    {
        /// <summary>
        /// 信息添加
        /// </summary>
        /// <param name="_obj"></param>
        /// <returns></returns>
        public static string CreateFinanceRecord(Model.LED.FinanceRecordBase _obj)
        {
            string status = (new SQLServerDAL.LED.FinanceRecordBase()).CreateFinanceRecord(_obj);

            string result = "";
            switch (status)
            {
                case "-1":
                    result = "存储过程执行错误!"; ///storedprocedure error
                    break;
                default:
                    result = status;
                    break;
            }

            return result;
        }

        /// <summary>
        /// 信息修改
        /// </summary>
        /// <param name="_obj"></param>
        /// <returns></returns>
        public static string ModifyFinanceRecord(Model.LED.FinanceRecordBase _obj)
        {
            string status = (new SQLServerDAL.LED.FinanceRecordBase()).ModifyFinanceRecord(_obj);

            string result = "";
            switch (status)
            {
                case "1":
                    result = "数据已入账!"; ///storedprocedure error
                    break;
                case "-1":
                    result = "存储过程执行错误!"; ///storedprocedure error
                    break;
                default:
                    result = status;
                    break;
            }

            return result;
        }

        /// <summary>
        /// 获取信息实体
        /// </summary> 
        /// <returns></returns>
        public static Model.LED.FinanceRecordBase GetObjById(string financerecordid)
        {
            return (new SQLServerDAL.LED.FinanceRecordBase()).GetObjById(financerecordid);  
        }

        /// <summary>
        /// 删除信息
        /// isLogical 是否逻辑删除(True 逻辑删除，False 物理删除)
        /// </summary>
        /// <param name="financerecordid">产品Id</param>
        /// <param name="isLogical">是否逻辑删除(True 逻辑删除，False 物理删除)</param>
        public static string Delete(string financerecordid, bool isLogical)
        {
            string status = (new SQLServerDAL.LED.FinanceRecordBase()).Delete(financerecordid, isLogical);

            string result = "";
            switch (status)
            {
                case "0":
                    result = "succeeded";
                    break;
                case "1":
                    result = "记录不存在！";
                    break;
                case "2":
                    result = "已入账，不允许删除！";
                    break;
                case "-1":
                    result = "存储过程执行错误！";
                    break;
                default:
                    result = status;
                    break;
            }

            return result;
        }
 
        /// <summary>
        /// 生成报表数据
        /// </summary> 
        public static string BuildingReport(int year, string createdby)
        {
            string status = "", result = "succeeded";
            SQLServerDAL.LED.FinanceRecordBase _obj = new SQLServerDAL.LED.FinanceRecordBase();
            for (int i = 1; i <= 12; i++)
            {
                status = _obj.BuildingReport(year, i, createdby);

                if (status != "0")
                {
                    result = status;
                    break;
                }
            }

            return result;
        }
    }
}
